How I resolved these issues:
- Animation set up
Save the Gif and convert to png files. Then, using "loadAnimation" to insert each single png file.
- Animation speed up
In the setup function, creating the new Group() and use ".addAni" to add ("random name", the variable that I store the loadAnimation);
In the draw function, write the code like:
if (random() > 0.995) {
let new_Gooma = new GoomaMonster.Sprite(width, height-100, 100, 100);
new_Gooma.scale = 0.3;
}
- Spining issue
Instead of using the collision, I use the overlap.
- How to kills Gooma
Considering to create another condition when mario overlap with Gooma, like:
if (mario.overlap(GoomaMonster[i])) {
// if (mario.overlap(GoomaMonster[i], {preventOverlap: true})) {
// check if the player is jumping
if (mario.position.y < height-90) {
// the player is jumping, remove the monster
GoomaMonster[i].remove();
score = score + 1;
} else {
// the player is not jumping, end the game
endGame();
}
} else {
GoomaMonster[i].position.x -= 0.5;
}
}
- Bullet issue
I find out the Push() will cause this problem. So I set up the bullet.velocity.x; bullet.velocity.y; bullet.position.y before push the bullets
- Moving issue
I addEventListener with ‘keydown':
document.addEventListener('keydown', function(event) {
if (event.key === 'a') {
mario.velocity.x = -10;
}
if (event.key === 'd') {
mario.velocity.x = 1;
}
});
- Mario.Remove() issue
Seems like I was trying to remove a sprite that has already been removed from the group. Therefore, I tried to make mario invisible, set mario's velocity to zero and set mario to its original position.
For MarioBullets, I tried to make mario invisible
mario.visible = false;
mario.velocity.x = 0;
mario.velocity.y = 0;
mario.position.x = 50;
mario.position.y = height-90;
for (var i = 0; i < MarioBullets.length; i++) {
MarioBullets[i].visible = false;
}
- Invisible Mariobullet
When player start the game, create a delay of 5 seconds before creating a new GoomaMonster and FlyMonster
let monsterDelay = -1;
if (monsterDelay === -1) {
monsterDelay = frameCount + 60 * 5;
}
if (frameCount >= monsterDelay) {
if (random() > 0.995) {
let new_Gooma = new GoomaMonster.Sprite(width, height-100, 100, 100);
// new GoomaMonster.Sprite(width, height-100, 50, 50);
// Gooma = createSprite(width,height-100,50,50);
// Gooma.addAnimation("running", Gooma_running);
new_Gooma.scale = 0.3;
// GoomaMonster.add(Gooma)
}
if (random() > 0.995) {
let new_fly = new flyMonster.Sprite(width, random(height-400, height - 200), 100, 100);
new_fly.scale = 0.3;
}
}